///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////

#include <stdlib.h>
#include <string>
#include <iostream> // The STL include.
#include "avatar.h"
#include "world.h"
#include "stringutil.h"

const int portNumber = 2950;

/*
 * This is where Scratch "starts". You can specify a port and it starts
 * running the MUD on specified port. Change PORTNUMBER to change the 
 * default port.
 */
int main( int argc, char *argv[] ) {    
    int port;    // The port number the Server runs off.
    bool copyover = false;
    

	port = portNumber; // Make sure we have a default port.
	if ( argc >= 2 ) {
		if ( str_cmp( argv[1], "-copyover" ) ) {
			copyover = true;
			SocketServer::Instance().SetHostSocket( atoi(argv[2]) );			     
		} else {
			if ( atoi( argv[1] ) <= 1024 ) { // Ports from 1024 and below are Reserved
				std::cout << "Port #" << argv[1] << " Reserved." << std::endl; 
				exit( 1 );
			} else if ( atoi( argv[1] ) > 65535 ) { // No ports above 65535 
				std::cout << "Port #" << argv[1] << " Out of Range. ( # > 65535 )" << std::endl;
				exit( 1 );
			} else { // The Port the user gave is usable.
				port = atoi( argv[1] ); 
			}
		}
	}

    // Start the game
	World::Instance().Exist( "Scratch is up", port, copyover );				
	return 0;
}
